/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/serializer/SerialContext.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: SerialContext.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.serializer;

public class SerialContext {

	private final SerialContext parent;

	private final Object object;

	private final Object fieldName;

	private int features = 0;

	public SerialContext(SerialContext parent, Object object, Object fieldName) {
		this.parent = parent;
		this.object = object;
		this.fieldName = fieldName;
	}

	public int getFeatures() {
		return features;
	}

	public void setFeatures(int features) {
		this.features = features;
	}

	public SerialContext getParent() {
		return parent;
	}

	public Object getObject() {
		return object;
	}

	public Object getFieldName() {
		return fieldName;
	}

	public String getPath() {
		if (parent == null) {
			return "$";
		} else {
			if (fieldName instanceof Integer) {
				return parent.getPath() + "[" + fieldName + "]";
			} else {
				return parent.getPath() + "." + fieldName;
			}

		}
	}

	@Override
	public String toString() {
		return getPath();
	}
}
